<template>
  <div>
    <h1>三级分类页面</h1>
    <el-tree :data="data" :props="defaultProps" @node-click="treenodeclick"></el-tree>
  </div>
</template>

<script>
import PubSub from 'pubsub-js'
export default {
  data() {
    return {
      data: [],
      defaultProps: {
        children: "children",
        label: "name"
      }
    };
  },
  created() {
    this.getDataList();
  },
  methods: {
    treenodeclick(data) {
      if (data.catLevel == 3) {
        PubSub.publish("tree-node-click", data);
      }
    },
    // 获取数据列表
    getDataList() {
      this.$http({
        url: this.$http.adornUrl("/product/category/tree/list"),
        method: "get",
        params: this.$http.adornParams()
      }).then(({ data }) => {
        this.data = data.page;
      });
    }
  }
};
</script>
